package com.lzb.findphone;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;

import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.lzb.findphone.basic.utils.StatusBarUtils;
import com.lzb.findphone.databinding.ActivityHomeBinding;
import com.lzb.findphone.fragment.FlashlightFragment;
import com.lzb.findphone.fragment.HomeFragment;
import com.lzb.findphone.fragment.MyFragment;
import com.lzb.findphone.fragment.RingtoneFragment;
import com.lzb.findphone.fragment.SoundFragment;
import com.lzb.findphone.utils.AppSpUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class HomeActivity extends BaseTabFragmentHomeActivity<ActivityHomeBinding> {

    @Override
    protected void onHandleStatusBar() {
        super.onHandleStatusBar();
        //设置状态栏字体颜色
        StatusBarUtils.setSystemStatusTextColor(true, this);
    }

    @Override
    protected void initView() {
        super.initView();
    }

    @Override
    protected void initData() {
        super.initData();
        if (AppSpUtils.getSetting() == null) {
            AppSpUtils.initSetting();
        }
    }

    @NonNull
    @Override
    protected List<BaseTabFragmentHomeActivity<ActivityHomeBinding>.FragmentViewBinder> getFragmentViewBinders() {
        List<FragmentViewBinder> listFragment = new ArrayList<>();
        listFragment.add(new FragmentViewBinder(HomeFragment.class, R.id.llHome));
        listFragment.add(new FragmentViewBinder(RingtoneFragment.class, R.id.llRingtone));
        listFragment.add(new FragmentViewBinder(SoundFragment.class, R.id.llSound));
        listFragment.add(new FragmentViewBinder(FlashlightFragment.class, R.id.llFlashlight));
        listFragment.add(new FragmentViewBinder(MyFragment.class, R.id.llMy));
        return listFragment;
    }

    @Override
    protected void onFragmentViewClick(View view) {
        clearSelection();
        int id = view.getId();
        if (id == R.id.llHome) {
            mDataBinding.ivHome.setImageResource(R.drawable.icon_findphone);
            mDataBinding.tvHome.setTextColor(Color.parseColor("#412FE9"));
        } else if (id == R.id.llRingtone) {
            mDataBinding.ivRingtone.setImageResource(R.drawable.icon_ring);
            mDataBinding.tvRingtone.setTextColor(Color.parseColor("#412FE9"));
        } else if (id == R.id.llSound) {
            mDataBinding.ivSound.setImageResource(R.drawable.icon_voice);
            mDataBinding.tvSound.setTextColor(Color.parseColor("#412FE9"));
        } else if (id == R.id.llFlashlight) {
            mDataBinding.ivFlashlight.setImageResource(R.drawable.icon_light);
            mDataBinding.tvFlashlight.setTextColor(Color.parseColor("#412FE9"));
        } else if (id == R.id.llMy) {
            mDataBinding.ivMy.setImageResource(R.drawable.icon_my);
            mDataBinding.tvMy.setTextColor(Color.parseColor("#412FE9"));
        }
    }

    @Override
    protected int getFragmentContainerId() {
        return R.id.flContainer;
    }

    @Override
    protected int onCreate() {
        return R.layout.activity_home;
    }

    private void clearSelection() {
        mDataBinding.ivHome.setImageResource(R.drawable.icon_findphone2);
        mDataBinding.tvHome.setTextColor(Color.parseColor("#9C9C9C"));
        mDataBinding.ivRingtone.setImageResource(R.drawable.icon_ring2);
        mDataBinding.tvRingtone.setTextColor(Color.parseColor("#9C9C9C"));
        mDataBinding.ivSound.setImageResource(R.drawable.icon_voice2);
        mDataBinding.tvSound.setTextColor(Color.parseColor("#9C9C9C"));
        mDataBinding.ivFlashlight.setImageResource(R.drawable.icon_light2);
        mDataBinding.tvFlashlight.setTextColor(Color.parseColor("#9C9C9C"));
        mDataBinding.ivMy.setImageResource(R.drawable.icon_my2);
        mDataBinding.tvMy.setTextColor(Color.parseColor("#9C9C9C"));
    }

}